{include app:admin.inc.header}
<!--tmpl-resource-->
{include app:admin.inc.top}


<div class="container-fluid content-body">
	<div class="main">
		<!-- left side start-->

		<section class="left-section">
			<dl id="leftNav" data-type="message">
				<dt><i class="glyphicon glyphicon-plus"></i> 信息管理</dt>
				{if in_case_array('admin/notice',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/notice/index}">公告管理</a></dd>
				{/if}
				{if in_case_array('admin/information',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/information/index}">资讯管理</a></dd>
				{/if}
				{if in_case_array('admin/singlepage',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/singlepage/index}">单页管理</a></dd>
				{/if}
				{if in_case_array('admin/brand',$priv) || empty($priv)}
				<dd><a class="mb active" href="{url /admin/brand/index}">特约品牌</a></dd>
				{/if}
				{if in_case_array('admin/adPlace',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/adPlace/index}">广告位管理</a></dd>
				{/if}
				{if in_case_array('admin/ad',$priv) || empty($priv)}
				<dd><a class="mbh" href="{url /admin/ad/index}">广告管理</a></dd>
				{/if}
			</dl>
		</section>

		<!-- left side end-->


		<!-- main content start-->
		<section class="right-section" id="right-section">
			{include admin.inc.bread}
			<h2 class="header">{$title}</h2>
			<!-- start of inner-frame -->
			<div class="inner-iframe">

				<div class="inner-container">
					<form role="form" class="content-add-form form-horizontal" id="content-add-form" autocomplete="off">
						<!--tmpl-fields-->
						<!-- input -->
						<div class="form-group">
							<label class="col-sm-2 control-label">
								<span class="asterisk">*</span>
								标题 
							</label>
							<div class="col-sm-6">
							<input  dtype="" class="form-control" maxlength="50" name="data[title]" placeholder="标题" required cname="标题" value="{$item[title]}" />
							</div>
						</div>
						<p class="help-block"></p>

						<div class="form-group">
							<label class="col-sm-2 control-label">货品类型</label>
							<div class="col-sm-4">
								<select name="data[cate]" class="form-control">
									{loop $cates $cate}
									<option {if $cate[type_name]==$item[cate]}selected{/if}  value="{$cate.type_name}">{$cate.type_name}</option>
									{/loop}
								</select>
							</div>
						</div>
						<p class="help-block"></p>

						<!-- input -->
						<div class="form-group">
							<label class="col-sm-2 control-label">
								<span class="asterisk">*</span>
								网址 
							</label>
							<div class="col-sm-6">
							<input  dtype="url" class="form-control" maxlength="255" name="data[url]" placeholder="网址" required cname="网址" value="{$item[url]}" />
							</div>
						</div>
						<p class="help-block"></p>
						
						<!-- image -->
						<div class="form-group">
							<label class="col-sm-2 control-label">LOGO</label>
							<div class="clearfix col-sm-4">
								<div class="fileWrap {$companyInfo[idcard_positive] != ''? 'active':''}">

									<div class="fileUpload">
										<input type="hidden" data-id="imgInput" name="data[logo]" id="cimg_url"  value="{$item[logo]}"/>
										<input class="fileBar" id="upload" name="src" type="text" accept="image/gif, image/jpeg, image/jpg, image/png, image/bmp" />
										<div class="btn_file" >
											<span class="icon_add"><i class="glyphicon glyphicon-plus">添加图片</i> </span>
										</div>
									</div>
									<div class="uploaded">
										<a class="btn_re" data-act="reUpload" href="javascript:;">删除重新上传</a>
										<p class="img" data-act="big"><img src="{$item[logo]}"/></p>
									</div>
								</div>
							</div>
							<div class="col-sm-4">
								* 图片比率为1:1 *
								<br>
								* 推荐大小为180 x 180 (px)
							</div>
						</div>
						<!-- input -->
						<div class="form-group">
							<label class="col-sm-2 control-label">
								<span class="asterisk">*</span>
								排序 
							</label>
							<div class="col-sm-4">
								<input  dtype="number" class="form-control" maxlength="{maxlength}" name="data[listorder]" placeholder="排序" required cname="排序" value="{if $item[listorder]}{$item[listorder]}{else}50{/if}" />
							</div>
							<div class="col-sm-4">
								*排序由小到大排序，数字越小，排得越前*
							</div>
						</div>
						<p class="help-block"></p>
						
						<!-- switch -->
						<div class="form-group">
							<label class="col-sm-2 col-sm-2 control-label">状态</label>
							<div class="col-sm-4">
								<input type="checkbox" id="switch-status" name="data[status]" class="bswitch" data-size="normal" {if $item[status]}checked{/if} data-on-text="启用" data-off-text="禁用">
							</div>
						</div>

						<!--tmpl-assocfields-->
						<div class="btn-group btn-group-or">
							<a href="{if $id==''}{$do_add_url}{else}{$do_edit_url}?id={$id}{/if}" class="btnlg mb ajaxproxy"
								proxy='{"method":"post", "location":"{$index_url}"}'>提交保存</a>

						</div>
					</form><!-- content add form -->
				</div>
			</div><!-- end of inner -->
		</section>
	</div>
</div>
{include admin.inc.footer}

<!--tmpl-script-->

<!-- pagescript -->
<script type="text/javascript">
	seajs.use("admin/brand_add",function (parameter){
		
		/**--tmpl-templatejavascript--**/
		
		<!--tmpl-templatejavascript-->
        var $upload = $(".fileWrap");
        parameter.upload_url="{$upload_url}";
		parameter.image_search_url="{$image_search_url}";
		parameter.image_list_url="{$image_list_url}";
		
		parameter.init();		
		parameter.upload({
			{if $item[logo]}datas : ['{$item[logo]}'],{/if}
        onSuccess : function(data) { //上传一张图片成功回调
            removeImage(data[data.length-2]);   ////当上传多张图片的时候，删除之前的所有图片
            var src = data[data.length-1];
            $upload.find('[data-id="imgInput"]').val(src);
            //图片显示
            $upload.find(".img img").attr("src",src);
            $upload.addClass("active");
        },
        onRemove : function(data) {
			/*$("#cimg_url").val("");*/
            $upload.find('[data-id="imgInput"]').val("");
            $upload.removeClass("active");
            removeImage(data); //用户删除的时候，把图片也连带删除
        }
    });

        $upload.on("click",'[data-act="reUpload"]',function(){
            var $wrap=$(this).closest(".fileWrap");
            //removeImage(data); //用户删除的时候，把图片也连带删除
            $wrap.find('[data-id="imgInput"]').val("");
            $wrap.removeClass("active");
        });
        //放大图片
        $('[data-act="big"]').on('click',function(){
            var src= $(this).children("img")[0].src;
            var height = $(window).height()*0.5+'px';
            var width = $(window).width()*0.5+'px';
            var img = '<img src="'+ src+'" style="width: '+width+';height'+height+'">';
            layer.open({
                type: 1,
                title: false,
                shadeClose: true,
                content:img
            })
        });
        function removeImage(data)
        {
            $.post('{url /admin/upload/delete}',{file : data,table : 'brand',field : 'logo' ,id : '{$item[id]}'},function (data){},'json');
        }
	});
</script>

</body>
</html>
